package com.ruoyi.web.controller.tool;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import com.ruoyi.web.controller.webContent.PlContentController;
import com.ruoyi.webContent.domain.HostCasEntry;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Hashtable;
import java.util.Map;

//使用单例模式存放各个网站的原始和处理后的数据
public class PlDataSetUtils {

    protected static final Logger logger = LoggerFactory.getLogger(PlDataSetUtils.class);


    //存储所有比赛原始信息，结构（网站：游戏名称：比赛list）
    private static JSONObject host_game_allMatch = new JSONObject();

    //存储所有比赛详情原始信息，结构（网站：游戏名称：网站比赛id:比赛详情信息）
    private static JSONObject host_game_allContent = new JSONObject();

    //存储加工后的能对应上的比赛信息 结构（游戏名称：hostA_hostB:{hostA:hostA比赛id,hostB:hostB比赛id}）
    private static JSONObject game_hostAB_sameMatch = new JSONObject();

    //存储加工后的比赛详情信息 结构（host:比赛id:比赛属性含转换后的赔率信息）
    private static JSONObject game_host_matchId_attr = new JSONObject();

    public static void setHostMatchIdAttr(String host , String matchId, HostCasEntry attr) {
        if(attr!=null){
            JSONPath.set(game_host_matchId_attr,host+".matchId_"+matchId, attr);
        }
    }
    public static HostCasEntry getHostMatchIdAttr(String host, String matchId) {
        JSONObject hostJson = game_host_matchId_attr.getJSONObject(host);
        JSONObject matchIdJson = hostJson.getJSONObject("matchId_"+matchId);
        return matchIdJson.toJavaObject(HostCasEntry.class);
    }
    public static JSONObject getHostMatchIdAttrTest(String host, String matchId) {
        return game_host_matchId_attr;
    }

    public static void setGameHostABSameMatch(String game, String hostAB , JSONArray sameMatch) {
        JSONPath.set(game_hostAB_sameMatch,game+"."+hostAB,sameMatch);
    }
    public static JSONObject getGameHostABSameMatch(String game) {
        JSONObject gameJson = game_hostAB_sameMatch.getJSONObject(game);
        return gameJson;
    }

    public static void setHostgameAllMatch(String host, String gameName, JSONArray allMatch) {
        JSONPath.set(host_game_allMatch,host+"."+gameName,allMatch);
    }
    public static JSONArray getHostgameAllMatch(String host, String gameName) {
        try {
            JSONObject hostJson = host_game_allMatch.getJSONObject(host);
            JSONArray gameJson = hostJson.getJSONArray(gameName);
            return gameJson;
        }catch (Exception e){
            logger.error("数据获取异常！！！网站："+host+"!!!游戏名称："+gameName+" >>>错误信息："+e);
        }
        return new JSONArray();
    }
    public static void setHostgameAllContent(String host, String gameName, Object allMatch) {
        JSONPath.set(host_game_allContent,host+"."+gameName,allMatch);
    }
    public static JSONObject getHostgameAllContent(String host, String gameName) {
        JSONObject hostJson = host_game_allContent.getJSONObject(host);
        JSONObject gameJson = hostJson.getJSONObject(gameName);
        return gameJson;
    }


}
